package llama.view.panels;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import llama.ctrl.ControllerFactory;
import llama.ctrl.IController;
import llama.ctrl.LogoutClientCtrl;
import llama.ctrl.NavigationCtrl;
import llama.ctrl.NavigationCtrl.NavigationType;

/**
 * The panel containing "Search Contact" and "Logout"
 * Shown below the contact list
 */
public class SearchLogoutPanel extends JPanel {
	private JButton btnLogout;
	private JButton btnSearch;

	/**
	 * Create the panel.
	 */
	public SearchLogoutPanel() {
		btnSearch = new JButton("Search Contact");
		btnSearch.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				NavigationCtrl nav = (NavigationCtrl) ControllerFactory.getController(NavigationCtrl.class);
				nav.setNavigation(NavigationType.SEARCH);
				nav.execute();
			}
		});
		
		setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		add(btnSearch);
		
		btnLogout = new JButton("Logout");
		btnLogout.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				IController out = ControllerFactory.getController(LogoutClientCtrl.class);
				out.execute();
			}
		});
		
		add(btnLogout);
	}
}
